<?
$data['mymove'] = 0;
$moves = $_REQUEST['spaces'];
	$wins = array(
		array(0,1,2),
		array(3,4,5),
		array(6,7,8),
		array(0,3,6),
		array(1,4,7),
		array(2,5,8),
		array(0,4,8),
		array(6,4,2)
		);
	foreach($wins as $a)
	{
		$x = 0; $o = 0; $e = 0;
		foreach($a as $i)
		{
			switch($moves[$i])
			{
				case 'X':
					$x++;
					break;
				case 'O':
					$o++;
					break;
				default:
					$e++;
					$data['mymove'] = $i;
			}
		}
		if($x == 3)
		{
			$data['message'] = 'You Win';
			$data['mymove'] = null;
			break;
		}
		if($o == 2 && $e==1)
		{
			$data['message'] = 'I Win';
			break;
		}
	}
echo json_encode($data);
